package com.cyc.pool;

import java.security.spec.ECField;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Executors 工具类 3大方法
 */
public class Demo1 {
    public static void main(String[] args) {
//        ExecutorService executorService = Executors.newSingleThreadExecutor();//单个线程
//         ExecutorService executorService =  Executors.newFixedThreadPool(5);//创建一个固定的线程池大小
        ExecutorService executorService = Executors.newCachedThreadPool();//可伸缩的
        try {
            for (int i = 0; i < 10; i++) {
                executorService.execute(()->{
                    System.out.println(Thread.currentThread().getName()+"  OK!!");
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            executorService.shutdown();
        }

//        线程池使用完，程序结束，关闭线程池
    }
}
